import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {

	/**
	 * map方法是用来给map task进程来调用的，每读取一行文本，就会调用一次map方法
	 */
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context)
			throws IOException, InterruptedException {
		// 拿到一行的内容，将其转换成文本
		String line = value.toString();
		// 将这一行切分成单词
		String[] words = line.split(" ");
		// 输出<单词,1>这样的KV
		for (String word : words) {
			context.write(new Text(word), new IntWritable(1));
		}
	}
}
